import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate';
Vue.use(Vuex)

export default new Vuex.Store({
    state:{
        items:JSON.parse(localStorage.getItem('items') || '[]'),
        list:[],
        current:{
            currentKey:-1,
        }
    },
    mutations:{
        setItems(state,data) {
            state.items = data;
            localStorage.setItem('items',JSON.stringify(data))
        },
        saveList(state,val){
            state.list.push(val)
        },
        setCurrentKey(state,val){
            state.current = val;
        }
    },
    actions:{

    },
    getters:{

    },
    plugins: [
        createPersistedState({
            storage: window.sessionStorage
        })
    ],
})
